/***********************************************
 This file is part of redia-bapps-main-ios.
 
 Copyright (c) 2015 Redia A/S
 
 Redia-bapps-main-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Redia-bapps-main-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-bapps-main-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */

//
//  BARelatedMaterialCell.m
//  redia-bapps-ios
//
//  Created by Henrik Lynbech on 08/10/13.
//  Copyright (c) 2013 redia. All rights reserved.
//

#import "BARelatedMaterialCell.h"
#import "BAUtils.h"
#import "UIImage+MultiplyColor.h"
#import "BALibrarySettings.h"

@interface BARelatedMaterialCell ()


@end

@implementation BARelatedMaterialCell

-(void)commonInitBARelatedMaterialCell {

}

-(id)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if (self) {
        // Initialization code
        [self commonInitBARelatedMaterialCell];
    }
    return self;
}

-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self commonInitBARelatedMaterialCell];
    }
    return self;
}

-(void)awakeFromNib
{
    BA_LABEL_SET_FONT_LIGHT(self.titleLabel);
    BA_LABEL_SET_FONT_LIGHT(self.noContentLabel);
    
    [self.highlightingView setBackgroundColor:[BALibrarySettings instance].getCustomerColorNormal];
    self.rightDisclosureImageView.image = [UIImage imageNamed:@"related-disclose-arrow-left" multiplyWithColor:[[BALibrarySettings instance] getCustomerColorNormal]];

}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self commonInitBARelatedMaterialCell];
    }
    return self;
}

-(void)setCategory:(BARelatedMaterialsTableCellCategory)category rowNumber:(int)rowNumber
{
    _category = category;
    
    if (!RD_IS_IPAD) {
        switch (rowNumber) {
            case 0:
                self.leftBackground.image = [UIImage imageNamed:@"cell_left_gray_gradient_background_1"];
                break;
                
            case 1:
                self.leftBackground.image = [UIImage imageNamed:@"cell_left_gray_gradient_background_2"];
                break;
                
            case 2:
                self.leftBackground.image = [UIImage imageNamed:@"cell_left_gray_gradient_background_3"];
                break;
                
            case 3:
                self.leftBackground.image = [UIImage imageNamed:@"cell_left_gray_gradient_background_4"];
                break;
                
            default:
                self.leftBackground.image = [UIImage imageNamed:@"cell_left_gray_gradient_background_5"];
                break;
        }
    }
    
    switch (category) {
        case BARelatedMaterialsTableCellCategoryHomeAt:
            self.titleLabel.text = @"Hvor er den hjemme";
            self.leftIconImageView.image = RD_IS_IPAD ? [UIImage imageNamed:@"related-ipad-icon-location"] : [UIImage imageNamed:@"related-icon-location"];
            break;
            
        case BARelatedMaterialsTableCellCategoryReviews:
            self.titleLabel.text = @"Anmeldelser";
            self.leftIconImageView.image = RD_IS_IPAD ? [UIImage imageNamed:@"related-ipad-icon-star"] : [UIImage imageNamed:@"related-icon-star"];
            break;
            
        case BARelatedMaterialsTableCellCategoryAboutCreator:
            self.titleLabel.text = @"Om forfatteren";
            self.leftIconImageView.image = RD_IS_IPAD ? [UIImage imageNamed:@"related-ipad-icon-info"] : [UIImage imageNamed:@"related-icon-info"];
            break;
            
        case BARelatedMaterialsTableCellCategoryRelatedLoans:
            self.titleLabel.text = @"Andre har også lånt";
            self.leftIconImageView.image = RD_IS_IPAD ? [UIImage imageNamed:@"related-ipad-icon-people"] : [UIImage imageNamed:@"related-icon-people"];
            break;
            
        case BARelatedMaterialsTableCellCategoryMoreByCreator:
            self.titleLabel.text = @"Andet af";
            self.leftIconImageView.image = RD_IS_IPAD ? [UIImage imageNamed:@"related-ipad-icon-books"] : [UIImage imageNamed:@"related-icon-books"];
            break;
            
        case BARelatedMaterialsTableCellCategoryMoreInSameSeries:
            self.titleLabel.text = @"Del af en serie";
            self.leftIconImageView.image = RD_IS_IPAD ? [UIImage imageNamed:@"related-ipad-icon-series"] : [UIImage imageNamed:@"related-icon-series"];
            break;
            
        default:
            break;
    }
}

-(void)setIsFetched:(BOOL)isFetched hasData:(BOOL)hasData
{
    _isFetched = isFetched;
    _hasData = hasData;
    [self.loadingIndicator stopAnimating];
    
    if (hasData) {
        self.rightDisclosureImageView.hidden=NO;
        self.noContentLabel.hidden=YES;
        self.userInteractionEnabled=YES;
    } else {
        self.rightDisclosureImageView.hidden=YES;
        self.noContentLabel.hidden=NO;
        if (RD_IS_IPAD) {
            //[self.contentView setAlpha:0.85];
            self.leftBackground.image = [UIImage imageNamed:@"relateds-list-sel-bg-ipad"];
            self.leftBackgroundRightSeparatorIPad.image = [UIImage imageNamed:@"relateds-list-right-sel-bg-ipad"];
        } else {
            self.titleLabel.textColor = [self.titleLabel.textColor colorWithAlphaComponent:0.5];
        }
    }
    
}

-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    self.myBackgroundView.backgroundColor = highlighted ? [UIColor colorWithWhite:221.0/255.0 alpha:1] : [UIColor colorWithWhite:242.0/255.0 alpha:1];
}

//
-(void)showHighlighting:(BOOL)highlight{
    [self.highlightingView setHidden:!highlight];
    if (self.category == BARelatedMaterialsTableCellCategoryHomeAt) {
        if (highlight) {
            self.titleLabel.text = @"Find den på hylden";
        } else {
            self.titleLabel.text = @"Hvor er den hjemme";
        }
    }
}

@end
